package asm.aop;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

/**
 * Created by User on 2017/11/28.
 */
public class AopMethodVisitor extends MethodVisitor implements Opcodes {
    public AopMethodVisitor(int i) {
        super(i);
    }

    public AopMethodVisitor(int i, MethodVisitor methodVisitor) {
        super(i, methodVisitor);
    }

    @Override
    public void visitCode() {
        super.visitCode();
        // invokevirtual 类asm.aop.AopInterceptor 方法 before 参数() 返回V
        this.visitMethodInsn(INVOKEVIRTUAL, "asm/aop/AopInterceptor", "before", "()V", false);
    }

    @Override
    public void visitInsn(int opcode) {
        if (opcode > IRETURN && opcode < RETURN) {
            // invokevirtual 类asm.aop.AopInterceptor 方法 after 参数() 返回V
            this.visitMethodInsn(INVOKEVIRTUAL, "asm/aop/AopInterceptor", "after", "()V", false);
        }

        super.visitInsn(opcode);
    }
}
